package com.lizhao;

import com.lizhao.ai.BehaviorTree;
import com.lizhao.ai.BehaviorTreeBuilder;
import com.lizhao.ai.common.EPolicy;
import com.lizhao.ai.impl.action.ActionAttack;
import com.lizhao.ai.impl.action.ActionPatrol;
import com.lizhao.ai.impl.action.ActionRunaway;
import com.lizhao.ai.impl.composite.ParallelImpl;
import com.lizhao.ai.impl.composite.SelectorImpl;
import com.lizhao.ai.impl.composite.SequenceImpl;
import com.lizhao.ai.impl.condition.ConditionIsEnemyDead;
import com.lizhao.ai.impl.condition.ConditionIsHealthLow;
import com.lizhao.ai.impl.condition.ConditionIsSeeEnemy;
import com.lizhao.ai.impl.decorator.Repeat;
import com.lizhao.astar.siki.AStar;
import com.lizhao.astar.siki.Point;

public class Main {

    public static void main(String[] args) {
        testBT();
//   testAStar();
    }

    //测试行为树
    public static void testBT() {
        BehaviorTreeBuilder builder = new BehaviorTreeBuilder();
        BehaviorTree behaviorTree = builder
                .addBehaviour(new SelectorImpl())//root
                    .addBehaviour(new SequenceImpl())//与行为
                        .addBehaviour(new ConditionIsSeeEnemy())//条件：是否看到敌人
                        .back()
                        .addBehaviour(new SelectorImpl())//或行为
                            .addBehaviour(new SequenceImpl())//与行为
                                .addBehaviour(new ConditionIsHealthLow())//条件：是否低血量
                                .back()
                                .addBehaviour(new ActionRunaway())//动作行为：逃跑
                                .back()
                           .back()
                        .addBehaviour(new ParallelImpl(EPolicy.RequireAll, EPolicy.RequireOne)) //并行节点
                            .addBehaviour(new ConditionIsEnemyDead(true))//条件：是否看到敌人
                            .back().
                            addBehaviour(new Repeat())
                                .addBehaviour(new ActionAttack())
                .back().back().back().back().back()
                        .addBehaviour(new ActionPatrol()).end();

        //模拟执行行为树
        for (int i = 0; i < 10; ++i) {
            System.out.println("--------------" + i + "------------");
            behaviorTree.tick();
        }

        System.out.println("pause ");
    }

    //测试A星算法
    public static void testAStar() {
        AStar aStar = new AStar();

        aStar.initMap();
        Point start = aStar.map[4][4];
        Point end = aStar.map[8][5];

        aStar.findPath(start, end);
        aStar.showPath(start, end);
        aStar.showLoad();
        System.out.println("Hello World! ");
    }

}
